/*
 * lab9C1.c
 *
 *
 * CSIS 248 Operating System Programming
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define SIZE1 10
#define SIZE2 12


int main( ){
   char a[SIZE1] = "Hello";
   char b[SIZE2] = "CSIS 248";

   int alen = strlen( a );
   int blen = strlen( b );

   printf("a = %s and has length = %d\n", a, alen );
   printf("b = %s and has length = %d\n", b, blen );
   printf("\n");
   printf("a = %p", a );
   printf(" and a points to: %c\n", *a);
   printf("b = %p", b );
   printf(" and b points to: %c\n\n", *b);


   /* Allocate memory for a copy of a + b */
   int clen = alen + blen + 1; // 1 is for the NUL character
   char* c = (char*) malloc( clen );

   printf("Allocated %d bytes for c.\n", clen );
   // first copy the "a" string
   strncpy( c, a, clen );
   int len1 = strlen( c );
   // next find where to start the next copy
   if (len1 < clen){
	   char* d = c + len1;
	   // and copy the "b" string
	   strncpy( d, b, clen-len1);
   }
   printf(" a + b = %s\n  and its length is %d.\n", c, (int) strlen( c ) );

}
